package com.lry.basic.jvm.invoke;

import org.omg.CORBA.OBJECT_NOT_EXIST;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/12/11
 */
public class Test {
    class GrandFarther{
        void say() throws Throwable {
            System.out.println("i am grandFarther");
        }
    }

    class Farther extends GrandFarther{
        void say() throws Throwable {
            System.out.println("i am farther");
        }
    }

    class Son extends Farther{
        void say() throws Throwable {
            MethodType mt = MethodType.methodType(void.class);
            //invokeSpecial,findSpecial:init,private,父类方法
            //invokeStatic,findStatic:static
            //invokeinterface:接口方法
            //invokevirtual:虚方法（除去上面这些并且非final）
            MethodHandle mh = MethodHandles.lookup().findSpecial(GrandFarther.class,"say",mt,getClass());
            mh.invoke(this);
        }
    }

    public static void main(String[] args) throws Throwable {
        Test test = new Test();
        Son son = test.new Son();
        son.say();
    }
}
